package Arrays;

import java.util.Stack;

/**
 * 作者:hfj
 * 功能:234.回文链表
 * 日期: 2025/11/11 16:24
 */
public class IsPalindrome1 {
    public boolean isPalindrome(ListNode head) {
        if(head == null){
            return true;
        }
        ListNode node = head;
        Stack<Integer> stack=new Stack<>();
        while(node != null){
            stack.push(node.val);
            node = node.next;
        }
        while(head != null){
            if(head.val != stack.pop()){
                return false;//不匹配直接返回
            }
            head = head.next;
        }
        return true;//是回文链表返回正
    }
}
